// import service from "../utils/request";
import { LoginType, RegisterType } from "../types";
import Mock from "mockjs";

// 注册接口
export const register = (data: RegisterType) => {
  if (data.username === "admin" && data.password === "123456") {
    return Mock.mock({
      code: 200,
      msg: "注册成功",
      data:null
    });
  } else {
    return Mock.mock({
      code: 500,
      msg: "注册失败，用户名或密码错误",
      data: null
    });
  }
};

// service.post({ url: "/auth/register", data });

export const login = (data: LoginType) => {
  if (data.username === "admin" && data.password === "123456") {
    return Mock.mock({
      code: 200,
      msg: "登录成功",
      data: {
        token: Mock.mock('@string("lower", 16)'), // 16位随机小写字符串
        userInfo: {
          id: Mock.mock('@id'),
          username: data.username,
          avatar: Mock.mock('@image("100x100", "#50B347", "#FFF", "avatar")'),
        },
      },
    });
  } else {
    return Mock.mock({
      code: 500,
      msg: "用户名或密码错误",
      data: null
    });
  }
};

// service.post({ url: "/auth/login", data });
